package com.keyingbo.leran.pattern.prototype;

import java.io.*;

/**
 * @Auther: KEYB
 * @Date: 2019-3-12 23:53
 * @Description:
 */
public class Cat implements Cloneable, Serializable {
    private  Wheel wheel;
    private  String model;
    public Cat(){}
    public Cat(Wheel wheel, String model) {
        this.wheel = wheel;
        this.model = model;
    }

    public Wheel getWheel() {
        return wheel;
    }

    public void setWheel(Wheel wheel) {
        this.wheel = wheel;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Cat clone(){
        Cat cat = new Cat();
        cat.setModel(this.model);
        cat.setWheel(this.wheel);
        return  cat;
    }

    public Cat deepClone(){
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream os = new ObjectOutputStream(bos);
            os.writeObject(this);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream is = new ObjectInputStream(bis);
            Cat cat = (Cat) is.readObject();
            return  cat;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return  null;
    }
}
